unit Class_ZBD_GL;

interface
uses
  Classes,SysUtils,Uni,UniEngine;

type
  TZBDGL=class(TUniEngine)
  private
    FZBDBHTJ  : string;
    FZBDFLBHTJ: Integer;
    FZBDBHYS  : string;
    FZBDFLBHYS: Integer;
  protected
    procedure SetParameters;override;
    function  GetStrInsert:string;override;
    function  GetStrUpdate:string;override;
    function  GetStrDelete:string;override;
  public
    function  GetStrsIndex:string;override;
  public
    function  GetNextIdex:Integer;overload;
    function  GetNextIdex(AUniConnection:TUniConnection):Integer;overload;
  public
    function  CheckExist(AUniConnection:TUniConnection):Boolean;override;
  public
    destructor  Destroy; override;
    constructor Create;  
  published
    property ZBDBHTJ  : string read FZBDBHTJ   write FZBDBHTJ;
    property ZBDFLBHTJ: Integer read FZBDFLBHTJ write FZBDFLBHTJ;
    property ZBDBHYS  : string read FZBDBHYS   write FZBDBHYS;
    property ZBDFLBHYS: Integer read FZBDFLBHYS write FZBDFLBHYS;    
  public
    class function  ReadDS(AUniQuery:TUniQuery):TUniEngine;override;
    class procedure ReadDS(AUniQuery:TUniQuery;var Result:TUniEngine);override;
    class function  CopyIt(AZBDGL:TZBDGL):TZBDGL;overload;        
    class procedure CopyIt(AZBDGL:TZBDGL;var Result:TZBDGL);overload;       
  end;

implementation

{ TZBDGL }
procedure TZBDGL.SetParameters;
begin
  inherited;
  with FUniSQL.Params do
  begin
    case FOptTyp of
      otAddx:
      begin
        ParamByName('ZBD_BH_TJ').Value := ZBDBHTJ;
        ParamByName('ZBD_FL_BH_TJ').Value := ZBDFLBHTJ;
        ParamByName('ZBD_BH_YS').Value := ZBDBHYS;
        ParamByName('ZBD_FL_BH_YS').Value := ZBDFLBHYS; 
      end;
      otEdit:
      begin
        ParamByName('ZBD_BH_TJ').Value := ZBDBHTJ;
        ParamByName('ZBD_FL_BH_TJ').Value := ZBDFLBHTJ;
        ParamByName('ZBD_BH_YS').Value := ZBDBHYS;
        ParamByName('ZBD_FL_BH_YS').Value := ZBDFLBHYS; 
      end;  
      otDelt:
      begin
        ParamByName('ZBD_BH_TJ').Value := ZBDBHTJ;
        ParamByName('ZBD_FL_BH_TJ').Value := ZBDFLBHTJ;
        ParamByName('ZBD_BH_YS').Value := ZBDBHYS;
        ParamByName('ZBD_FL_BH_YS').Value := ZBDFLBHYS; 
      end;  
    end;
  end;
end;

function TZBDGL.CheckExist(AUniConnection: TUniConnection): Boolean;
begin
  Result:=CheckExist('TBL_ZBD_GL',['ZBD_BH_TJ',ZBDBHTJ,'ZBD_FL_BH_TJ',ZBDFLBHTJ,'ZBD_BH_YS',ZBDBHYS,'ZBD_FL_BH_YS',ZBDFLBHYS],AUniConnection);
end;

function TZBDGL.GetNextIdex: Integer;
begin

end;

function TZBDGL.GetNextIdex(AUniConnection: TUniConnection): Integer;
begin

end;

function TZBDGL.GetStrDelete: string;
begin
  Result:='DELETE FROM TBL_ZBD_GL WHERE   ZBD_BH_TJ=:ZBD_BH_TJ AND ZBD_FL_BH_TJ=:ZBD_FL_BH_TJ AND ZBD_BH_YS=:ZBD_BH_YS AND ZBD_FL_BH_YS=:ZBD_FL_BH_YS';
end;

function TZBDGL.GetStrInsert: string;
begin
  Result:='INSERT INTO TBL_ZBD_GL'
         +'    ( ZBD_BH_TJ, ZBD_FL_BH_TJ, ZBD_BH_YS, ZBD_FL_BH_YS)'
         +'    VALUES'
         +'    (:ZBD_BH_TJ,:ZBD_FL_BH_TJ,:ZBD_BH_YS,:ZBD_FL_BH_YS)';
end;

function TZBDGL.GetStrsIndex: string;
begin
  Result:=Format('%S-%D-%S-%D',[ZBDBHTJ,ZBDFLBHTJ,ZBDBHYS,ZBDFLBHYS]);
end;

function TZBDGL.GetStrUpdate: string;
begin
  raise Exception.Create('CAN NOT SUPPORT GETSTRUPDATE METHOD.CAUSE ALL THIS TABLE FILEDS ARE PRIMARY KEY.')
end;

constructor TZBDGL.Create;
begin

end;

destructor TZBDGL.Destroy;
begin

  inherited;
end;

class function TZBDGL.ReadDS(AUniQuery: TUniQuery): TUniEngine;
begin
  Result:=TZBDGL.Create;
  with TZBDGL(Result) do
  begin
    ZBDBHTJ  :=AUniQuery.FieldByName('ZBD_BH_TJ').AsString;
    ZBDFLBHTJ:=AUniQuery.FieldByName('ZBD_FL_BH_TJ').AsInteger;
    ZBDBHYS  :=AUniQuery.FieldByName('ZBD_BH_YS').AsString;
    ZBDFLBHYS:=AUniQuery.FieldByName('ZBD_FL_BH_YS').AsInteger;
  end;  
end;

class procedure TZBDGL.ReadDS(AUniQuery: TUniQuery; var Result: TUniEngine);
begin
  if Result=nil then Exit;
  with TZBDGL(Result) do
  begin
    ZBDBHTJ  :=AUniQuery.FieldByName('ZBD_BH_TJ').AsString;
    ZBDFLBHTJ:=AUniQuery.FieldByName('ZBD_FL_BH_TJ').AsInteger;
    ZBDBHYS  :=AUniQuery.FieldByName('ZBD_BH_YS').AsString;
    ZBDFLBHYS:=AUniQuery.FieldByName('ZBD_FL_BH_YS').AsInteger;
  end;  
end;

class function  TZBDGL.CopyIt(AZBDGL: TZBDGL): TZBDGL;
begin
  Result:=TZBDGL.Create;
  TZBDGL.CopyIt(AZBDGL,Result)
end;

class procedure TZBDGL.CopyIt(AZBDGL:TZBDGL;var Result:TZBDGL);
begin
  if Result=nil then Exit;
  Result.ZBDBHTJ  :=AZBDGL.ZBDBHTJ;
  Result.ZBDFLBHTJ:=AZBDGL.ZBDFLBHTJ;
  Result.ZBDBHYS  :=AZBDGL.ZBDBHYS;
  Result.ZBDFLBHYS:=AZBDGL.ZBDFLBHYS;
end;

end.

